<div style="height: 600px">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=823e9622da7839d78cb7cc583406e027&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
{{--    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>--}}
    <div style="height: 90%;top:40px" id="dituContent"></div>
    <script type="text/javascript">
        window.onload = function() {
            map.plugin(["AMap.ToolBar"], function() {
                map.addControl(new AMap.ToolBar());
            });
            if(location.href.indexOf('&guide=1')!==-1){
                map.setStatus({scrollWheel:false})
            }
        }
        var lng;//经度
        var lat;//维度
        var marker1 = [];
        var map;
        var markerContentBlue = '' +
            '<div>' +
            '   <img  style ="width:25px;height:34px;" src="/images/common/mapblue.png">' +
            '</div>';
        $(document).ready(function(){
            if(lng == null || lat == null){
                map = new AMap.Map('dituContent',{
                    resizeEnabel: false,
                });
                marker1[0] = new AMap.Marker({
                    position:new AMap.LngLat(116.39, 39.9),
                    content: markerContentBlue,
                    offset: new AMap.Pixel(-13, -14)//移动距离：绝对坐标、相对坐标
                });
                map.add(marker1[0]);
            }else{
                map = new AMap.Map('dituContent',{
                    resizeEnable: false,
                    zoom: 10,
                    center: [lng,lat]
                });
                marker1[0] = new AMap.Marker({
                    position:new AMap.lngLat(lng,lat),
                    offset: new AMap.Pixel(-13,-14),
                    content: markerContentBlue
                });
                map.add(marker1[0]);
            }
            map.on('click', function (e) {
                //1.清楚地图标注
                map.remove(marker1[0]);
                //2.经纬度赋值
                $("input[name='lng']").val(e.lnglat.getLng());
                $("input[name='lat']").val(e.lnglat.getLat());
                //3.根据经纬度反向地理编码获取地图定位赋值
                var geocoder;
                var lnglatXY = new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat());
                //加载地理编码插件
                map.plugin(["AMap.Geocoder"], function () {
                    geocoder = new AMap.Geocoder({
                        radius: 1000, //以已知坐标为中心点，radius为半径，返回范围内兴趣点和道路信息
                        extensions: "all"//返回地址描述以及附近兴趣点和道路信息，默认"base"
                    });
                    //返回地理编码结果
                    AMap.event.addListener(geocoder, "complete", function (e) {
                        //$("#address").val(e.regeocode.formattedAddress);
                        var address;
                        if(e.regeocode.addressComponent.neighborhood) {
                            address = e.regeocode.addressComponent.neighborhood;
                        } else {
                            address = e.regeocode.addressComponent.street + e.regeocode.addressComponent.township + e.regeocode.addressComponent.streetNumber;
                        }
                        $("input[name='address']").val(address);
                    });
                    //逆地理编码
                    geocoder.getAddress(lnglatXY);
                });
                //4.添加标注
                marker1[0] = new AMap.Marker({
                    position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
                    offset: new AMap.Pixel(-13, -14),
                    content: markerContentBlue,
                });
                map.add(marker1[0]);
            })
            //根据输入框标注地图
            var auto = new AMap.Autocomplete({
                input: $("input[name='address']").attr('id'),
                city: $("input[name='city']").text()
            });
            var placeSearch = new AMap.PlaceSearch({
                city: $("input[name='city']").text(),
            });
            //构造地点查询类
            AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
            function select(e) {
                $("input[name='lng']").val(e.poi.location.lng);
                $("input[name='lat']").val(e.poi.location.lat);
                map.remove(marker1[0]);
                placeSearch.search(e.poi.name);  //关键字查询查询
                map.setZoomAndCenter(15, [e.poi.location.lng, e.poi.location.lat]); //同时设置地图层级与中心点
            }
        })
    </script>
</div>
